// pages/qualityControl/equipmentManage/detailEquipment/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    winHeight:"",
    serialOrLotNumber:"",
    typeName:"",
    typeValue:"",
    code:"",
    model:"",
    extendList:"",
    reportCode:"",
    calibrationDate:"",
    dueDate:"",
    pressure:"",
    temperature:"",
    calibrationFactor:"",
    access:"",
    num:"",
    param:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let self = this
    let that = this;
    wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        var calc = clientHeight * rpxR - 140;
        console.log(calc)
        that.setData({
          winHeight: calc
        });
      }
    });
     const eventChannel = this.getOpenerEventChannel();
		// 监听 index页面定义的toHome 事件
		eventChannel.on('toEquipmentdetail', (res) => {
      this.setData({
        num:res.item.typeValue=='1'?res.item.extendList.length:0,
        serialOrLotNumber:res.item.serialOrLotNumber,
        typeName:res.item.typeName,
        typeValue:res.item.typeValue,
        code:res.item.code,
        model:res.item.model,
        calibrationFactor:res.item.typeValue=='0'?res.item.extendList[0].calibrationFactor:"",
        // access:res.item.extendList[0].calibrationFactor,
        extendList:res.item.extendList,
        reportCode:res.item.reportCode,
        calibrationDate:res.item.calibrationDate,
        dueDate:res.item.dueDate,
        pressure:res.item.pressure,
        temperature:res.item.temperature,
        param:res.item
      })
      console.log(res,'页面传值')
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  edtion(){
    let self = this
    wx.navigateTo({
      url: '../editEquipment/index',
          success:function(res){
           res.eventChannel.emit('toequipmentEdtion',{item:self.data.param})
    }
  })
  },
  deleteOne(){
    let self = this
    wx.showModal({
      title: '提示',
      content: '确定删除？',
      success: function (res) {
        if (res.confirm) {
          self
          .axios
          .remove("QualityControlEquipment", self.data.param.id)
          .then(function () {
            wx.showToast({
              title: '删除成功',
              icon: 'succes',
              duration: 1000,
              mask:true
          })
          wx.navigateBack({
            delta: 1
          })
          })
          .catch(function (response) {
          });
        } else {
          console.log('取消')
        }
      }
    })



  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})